/**
 * 
 */
package travibot.resource;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

/**
 * @author tajzivit
 * 
 */
public class ResourceHelper {

    public static String getKeyValue(String resource, String key) {

        return ResourceBundle.getBundle(resource).getString(key);
    }

    /**
     * Gets List of values according to this mask [key].ANY_OTHER_SUBKEY from
     * the specified resource file
     * 
     * @param resource
     * @param key
     * @return
     * @author macekpet
     */
    public static Map<String, String> getKeyValues(String resource, String key) {

        Map<String, String> values = new HashMap<String, String>();
        Enumeration<String> keys = ResourceBundle.getBundle(resource).getKeys();
        while (keys.hasMoreElements()) {
            String k = keys.nextElement();
            if (k.startsWith(key + ".")) {
                //String subkey = k.substring(k.indexOf("."));
                values.put(k, ResourceBundle.getBundle(resource).getString(k));
            }
        }
        return values;
    }
}
